<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>发射站所属组管理</title>
    <meta name="decorator" content="nblank"/>
</head>
<body>
<div class="content container">
    <h2 class="page-title">发射站所属组管理
        <small> &nbsp;发射站所属组${not empty param.id?'修改':'添加'}</small>
    </h2>
    <section class="widget widget-tabs widget-table-overflow ">
        <header>
            <ul class="nav nav-tabs">
                <li><a href="${ctx}/biz/sgroup/sgroup">发射站列表</a></li>
                <li><a href="${ctx}/biz/sgroup?station.id=${sgroup.station.id}">组列表&nbsp;(${sgroup.station.name})</a>
                </li>
                <li class="active"><a
                        href="${ctx}/biz/sgroup/form?station.id=${sgroup.station.id}">组${not empty param.id?'修改':'添加'}&nbsp;(${sgroup.station.name})</a>
                </li>
            </ul>
        </header>
        <div class="body tab-content">
            <form:form id="inputForm" modelAttribute="stationGroup" action="${ctx}/biz/sgroup/save" method="post"
                       class="form-horizontal">
                <form:hidden path="id"/>
                <form:hidden path="station.id"/>
                <div class="form-group">
                    <label for="grpType" class="control-label col-sm-4"><span class="help-inline"><font
                            color="red">*</font> </span> 组类型:</label>
                    <div class="col-sm-8">
                        <form:select path="grpType" class="selectpicker" data-style="btn-primary">
                            <form:option value="" label="请择选"/>
                            <form:options items="${groupTypeMap}"
                                          itemValue="key" itemLabel="value" htmlEscape="false"/>
                        </form:select>
                        <p id="grpTypeTip1" style="display: none">请选择组类型</p>
                        <%--<p id="grpTypeTip2" style="display: none">同一站点只能存在一组基础组</p>--%>
                    </div>
                </div>
                <div class="form-group">
                    <label for="group.id" class="control-label col-sm-4"><span class="help-inline"><font
                            color="red">*</font> </span> 设备组:</label>
                    <div class="col-sm-8">
                        <form:select path="group.id" data-width="auto" data-style="btn-primary"
                                     class="selectpicker">
                            <form:option value="" label="请选择" />
                            <form:options items="${egList}" itemValue="id" itemLabel="name" />
                        </form:select>
                        <p id="groupTip" style="display: none">请选择设备组</p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label col-sm-4"><span class="help-inline"><span style="color:red;">*</span> </span>
                        名称:</label>
                    <div class="col-sm-4">
                        <form:input id="name" path="name" htmlEscape="false" maxlength="50"
                                    class="form-control input-transparent"/>
                    </div>
                </div>

                <div class="form-actions">
                    <div class="text-align-center">
                        <input id="btnCancel" class="btn btn-default" type="button"
                               style="margin-left: -50px;min-width:100px;" value="返 回" onClick="history.go(-1)"/>
                        <input id="btnSubmit" class="btn btn-primary" style="margin-left:50px;min-width:100px;"
                               type="submit" value="保 存"/>&nbsp;
                    </div>
                </div>
            </form:form>
        </div>
    </section>
</div>
<script type="text/javascript">
    $(function () {
        if($('#grpType').val()=="") {
            <%--if(${baseGroupCount}!=0)--%>
            <%--{--%>
                <%--$("#grpTypeTip2").css("display", "block");--%>
            <%--}--%>
            $('#group\\.id').attr("disabled", true);
            $('#group\\.id option:not(:first)').remove();
            $('#group\\.id').change().selectpicker('refresh');
        }else {
            $('#grpType').attr("disabled", true);
            $('#grpType').change().selectpicker('refresh');
        }

        $('#grpType').on('changed.bs.select', function (e) {
            if($('#grpType').val()==""){
                $("#grpTypeTip1").css("display","block");
            }else{
                $("#grpTypeTip1").css("display","none");
            }
            console.info($('#grpType').val()+"-------");
            $('#group\\.id').attr("disabled",true);
            $('#group\\.id option:not(:first)').remove();
            $('#group\\.id').change().selectpicker('refresh');
            console.info("after");
            $.ajax({
                type: "POST",
                url: "${ctx}/biz/equgroup/findListByType",
                data: "type=" + ($('#grpType').val()==""?1:$('#grpType').val()),
                dataType: "json",
                success: function (dataMap) {
                        $.each(dataMap, function (i, item) {
                            <%--if(${baseGroupCount}!=0 && item.type =="1"){--%>
                                <%--return;--%>
                            <%--}else {--%>
                                $("<option value='" + item.id + "'>" + item.name + "</option>").appendTo("#group\\.id");
                                $('#group\\.id').attr("disabled", false);
                                $("#group\\.id").change().selectpicker('refresh');
//                            }
                        });


                }
            });
        });

        $("#inputForm").validate({
            rules: {
                "name": {
                    required:true
                }
            },
            messages:{
                "name":{
                    required:"必埴项"
                }
            },
            invalidHandler: function (event, validator) {
                $("#btnSubmit").attr("disabled", false);
            },
            submitHandler: function (form) {
                if($('#group\\.id').val()==""){
                    $("#groupTip").css("display","block");
                }else if($('#grpType').val()==""){
                    $("#grpTypeTip1").css("display","block");
                }else{
                    $(form).find(":submit").attr("disabled", true).attr("value", "提交中...");
                    $(form).ajaxSubmit({
                        success: function (result) {
                            Messenger().post("操作成功!");
                            pxTrigDlg("${ctx}/biz/sgroup?station.id=${sgroup.station.id}");
                        }
                    })
                }
            }
        })
    });
</script>

</body>
</html>